import Vue from 'vue'
import VueRouter from 'vue-router'
import Main from '@/views/Main.vue'
import Login from '@/views/Login.vue'
import DingDing from '@/views/DingDing.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/redirect',
    component: Main,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect')
      }
    ]
  },
  {
    path: '/',
    component: Login,
  },
  {
    path: '/dingding',
    component: DingDing,
  },
  {
    path: '/',
    component: Main,
    redirect: '/index',
    children: [
      {
        path: '/index',
        component: () => import('@/views/MainPage/index/index'),
        name: 'Index',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    name: "shipperManager",
    path: "/shipperManager",
    hidden: false,
    component: Main,
    children: [
      {
        path: 'index',
        component: () => import('@/views/MainPage/shipperManager/index'),
        name: 'shipperManagerIndex',
        meta: { title: '货主管理', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    name: "driverCarManager",
    path: "/driverCarManager",
    hidden: false,
    component: Main,
    meta: {
      "title": "司机车辆管理",
      "icon": "system",
      "link": null
    },
    children: [
      {
        path: 'driverAuditing',
        component: () => import('@/views/MainPage/driverCarManager/driverAuditing'),
        name: 'driverAuditing',
        meta: { title: '司机审核', icon: 'dashboard', affix: true }
      },
      {
        path: 'carAuditing',
        component: () => import('@/views/MainPage/driverCarManager/carAuditing'),
        name: 'carAuditing',
        meta: { title: '车辆审核', icon: 'dashboard', affix: true }
      },
      {
        path: 'driverList',
        component: () => import('@/views/MainPage/driverCarManager/driverList'),
        name: 'driverList',
        meta: { title: '司机列表', icon: 'dashboard', affix: true }
      },
    ]
  },
  {
    name: "waybillManagement",
    path: "/waybillManagement",
    hidden: false,
    component: Main,
    meta: {
      "title": "运单管理",
      "icon": "system",
      "link": null
    },
    children: [
      {
        path: 'allList',
        component: () => import('@/views/MainPage/waybillManagement/allList'),
        name: 'allList',
        meta: { title: '总运单列表', icon: 'dashboard', affix: true }
      },
      {
        path: 'inList',
        component: () => import('@/views/MainPage/waybillManagement/inList'),
        name: 'inList',
        meta: { title: '进行中运单', icon: 'dashboard', affix: true }
      },
      {
        path: 'suspendList',
        component: () => import('@/views/MainPage/waybillManagement/suspendList'),
        name: 'suspendList',
        meta: { title: '已暂停运单', icon: 'dashboard', affix: true }
      },
      {
        path: 'trackList',
        component: () => import('@/views/MainPage/waybillManagement/trackList'),
        name: 'trackList',
        meta: { title: '分运单追踪', icon: 'dashboard', affix: true }
      },
    ]
  },
  {
    name: "moneyManagment",
    path: "/moneyManagment",
    hidden: false,
    component: Main,
    meta: {
      "title": "财务管理",
      "icon": "system",
      "link": null
    },
    children: [
      {
        path: 'auditing',
        component: () => import('@/views/MainPage/moneyManagment/auditing'),
        name: 'auditing',
        meta: { title: '财务审核', icon: 'dashboard', affix: true }
      },
      {
        path: 'collect',
        component: () => import('@/views/MainPage/moneyManagment/collect'),
        name: 'collect',
        meta: { title: '汇总代开', icon: 'dashboard', affix: true }
      },
      {
        path: 'shipperStream',
        component: () => import('@/views/MainPage/moneyManagment/shipperStream/shipperStream'),
        name: 'shipperStream',
        meta: { title: '货主流水', icon: 'dashboard', affix: true }
      },
      {
        path: 'driverStream',
        component: () => import('@/views/MainPage/moneyManagment/driverStream'),
        name: 'driverStream',
        meta: { title: '司机流水', icon: 'dashboard', affix: true }
      },
      {
        path: 'vaildate',
        component: () => import('@/views/MainPage/moneyManagment/payValidate/payValidate'),
        name: 'vaildate',
        meta: { title: '支付结果验证', icon: 'dashboard', affix: true }
      },
      {
        name: "invoiceManage",
        path: "invoiceManage",
        component: () => import('@/views/MainPage/moneyManagment/invoiceManage/invoiceManage'),
        meta: { title: '发票管理', icon: 'dashboard', affix: true }
      },
      {
        name: "invoiceDetail",
        path: "invoiceDetail",
        component: () => import('@/views/MainPage/moneyManagment/invoiceDetail/invoiceDetail'),
        meta: { title: '发票明细', icon: 'dashboard', affix: true }
      },
      {
        name: "bankCardManagment",
        path: "bankCardManagment",
        component: () => import('@/views/MainPage/moneyManagment/bankCardManagment/bankCardManagment'),
        meta: { title: '常用银行卡管理', icon: 'dashboard', affix: true }
      },
      {
        name: "prePay",
        path: "prePay",
        component: () => import('@/views/MainPage/moneyManagment/prePay/prePay'),
        meta: { title: '预支付列表', icon: 'prePay', affix: true }
      },

    ]
  },
  {
    name: "GoodsManagment",
    path: "/goodsManagment",
    hidden: false,
    component: Main,
    children: [
      // {
      //   path: 'release',
      //   component: () => import('@/views/MainPage/GoodsManagment/release'),
      //   name: 'release',
      //   meta: { title: '发布货源', icon: 'dashboard', affix: true }
      // },
      {
        path: 'list',
        component: () => import('@/views/MainPage/GoodsManagment/list'),
        name: 'list',
        meta: { title: '货源列表', icon: 'dashboard', affix: true }
      },
      // {
      //   name: "robWaybill",
      //   path: "robWaybill",
      //   component: () => import('@/views/MainPage/GoodsManagment/robWaybill'),
      //   meta: { title: '抢单列表', icon: 'dashboard', affix: true }
      // }
    ]
  },
  {
    name: "PageConfig",
    path: "/pageConfig",
    hidden: false,
    component: Main,
    children: [
      // {
      //   path: 'release',
      //   component: () => import('@/views/MainPage/GoodsManagment/release'),
      //   name: 'release',
      //   meta: { title: '发布货源', icon: 'dashboard', affix: true }
      // },
      {
        path: 'list',
        component: () => import('@/views/MainPage/pageConfig/list'),
        name: 'list',
        meta: { title: '配置列表', icon: 'dashboard', affix: true }
      },
      {
        path: 'edit',
        component: () => import('@/views/MainPage/pageConfig/edit'),
        name: 'edit',
        meta: { title: '配置数据', icon: 'dashboard', affix: true }
      },
      // {
      //   name: "robWaybill",
      //   path: "robWaybill",
      //   component: () => import('@/views/MainPage/GoodsManagment/robWaybill'),
      //   meta: { title: '抢单列表', icon: 'dashboard', affix: true }
      // }
    ]
  },
  {
    name: "VIP",
    path: "/vip",
    hidden: false,
    component: Main,
    children: [
      {
        path: 'auditing',
        component: () => import('@/views/MainPage/VIPManagement/VIPAuditing'),
        name: 'list',
        meta: { title: '会员审核', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    name: "set",
    path: "/set",
    hidden: false,
    component: Main,
    children: [
      {
        path: 'index',
        component: () => import('@/views/MainPage/Set/index/index'),
        name: 'setindex',
        meta: { title: '总配置', icon: 'dashboard', affix: true }
      },
      {
        path: 'info',
        component: () => import('@/views/MainPage/Set/info/index'),
        name: 'info',
        meta: { title: '平台信息', icon: 'dashboard', affix: true }
      },
      {
        path: 'userVersion',
        component: () => import('@/views/MainPage/Set/userVersion/index'),
        name: 'user_Version',
        meta: { title: '用户版本', icon: 'version', affix: true }
      },
      {
        path: 'log',
        component: () => import('@/views/MainPage/Set/Log/index'),
        name: 'log',
        meta: { title: '平台日志', icon: 'log', affix: true }
      }
    ]
  },
  {
    name: "withdraw",
    path: "/withdraw",
    hidden: false,
    component: Main,
    meta: {
      "title": "提现管理",
      "icon": "system",
      "link": null
    },
    children: [
      {
        path: 'allList',
        component: () => import('@/views/MainPage/withdraw/allList'),
        name: 'allList',
        meta: { title: '提现管理', icon: 'dashboard', affix: true }
      }
    ]
  },
  { path: '*', redirect: '/' }
]

// 防止连续点击多次路由报错
let routerPush = VueRouter.prototype.push;
let routerReplace = VueRouter.prototype.replace;
// push
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(err => err)
}
// replace
VueRouter.prototype.replace = function push(location) {
  return routerReplace.call(this, location).catch(err => err)
}

const router = new VueRouter({
  mode: 'hash',
  scrollBehavior: () => ({ y: 0 }),
  routes
})

export default router
